package sctu.edu.java.year2016.team01.xuhanmei.day20160617;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

/**
 * Created by Administrator on 2016/6/17.
 */
public class VisibleCalendar {
    public static void main(String[] args) {
        System.out.println("请输入一个日期：格式如:2016-06-17");
        Scanner today=new Scanner(System.in);

        String temp=today.nextLine();

        DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
        try {

            Date date=format.parse(temp);

            Calendar calendar= new GregorianCalendar();
            calendar.setTime(date);

            int day=calendar.get(Calendar.DATE);//获取当天的日期
            calendar.set(Calendar.DATE, 1);//将日期设置为1日
         //   System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
            System.out.println();

            int maxday=calendar.getActualMaximum(Calendar.DATE);

            System.out.println("日\t一\t二\t三\t四\t五\t六");

            for(int i=1;i<(calendar.get(Calendar.DAY_OF_WEEK));i++){
                System.out.print("\t");
            }

            for(int i=1;i<=maxday;i++){
                if(i==day){
                    System.out.print("*");
                }
                System.out.print(i+"\t");

                int w=calendar.get(Calendar.DAY_OF_WEEK);
                if(w==Calendar.SATURDAY){//星期六就换行
                    System.out.println();
                }
                calendar.add(Calendar.DATE, 1);
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }


    }
}
